package com.sg.service.biz.calc.impl;

import cn.hutool.core.bean.BeanUtil;
import com.sg.common.exception.Assert;
import com.sg.common.util.RedisUtil;
import com.sg.dto.biz.calc.req.ImplementPerfAchievementStatisticsComReqDto;
import com.sg.dto.biz.calc.res.ImplementPerfAchievementStatisticsComRespDto;
import com.sg.dto.integration.app.QueryTargetContetCycleDetailComReqDto;
import com.sg.dto.integration.app.QueryTargetContetCycleDetailComRespDto;
import com.sg.dto.integration.app.StatisticsWorkCycleAchievementNumsComReqDto;
import com.sg.dto.integration.app.StatisticsWorkCycleAchievementNumsComRespDto;
import com.sg.service.biz.calc.NullService;
import com.wicket.okrapp.integration.FwAppNullClient;
import com.wicket.okrapp.integration.TargetCalcService;
import org.apache.skywalking.apm.toolkit.trace.Tag;
import org.apache.skywalking.apm.toolkit.trace.Tags;
import org.apache.skywalking.apm.toolkit.trace.Trace;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.stream.Collectors;

/**
 * @author ：
 * @version 1.0
 * @date ：
 */
@Service
public class NullServiceImpl implements NullService {

    @Resource
    private RedisUtil redisUtil;
    @Resource
    private TargetCalcService fwAppTargetCalcClient;
    @Resource
    private FwAppNullClient fwAppNullClient;

    /**
     * D4执行绩效成果统计-被评对象[9286]
     * gen by moon at 4/5/2024, 9:39:10 PM
     */
    @Trace(operationName = "D4执行绩效成果统计-被评对象")
    @Tags({@Tag(key = "参数", value = "arg[0]"),
            @Tag(key = "返回值", value = "returnedObj")})
    @Transactional(rollbackFor = Exception.class)
    @Override
    public ImplementPerfAchievementStatisticsComRespDto implementPerfAchievementStatisticsCom(ImplementPerfAchievementStatisticsComReqDto reqDto) {


        StatisticsWorkCycleAchievementNumsComRespDto statisticsWorkCycleAchievementNumsComRespDto_1 = null;
        if ((reqDto != null && reqDto.getTargetCycleContentTypeCode() != null && reqDto.getTargetCycleContentTypeCode().equals("TARGET") && reqDto != null && reqDto.getIsLastCycle() != null && reqDto.getIsLastCycle().equals("TRUE"))) {
            //if((D4执行绩效成果统计(公共).关联目标内容类型编码 等于 目标 and D4执行绩效成果统计(公共).是否末级周期 等于 是))  66147

            QueryTargetContetCycleDetailComRespDto queryTargetContetCycleDetailComRespDto = null;
            QueryTargetContetCycleDetailComReqDto queryTargetContetCycleDetailComReqDto = new QueryTargetContetCycleDetailComReqDto();
            queryTargetContetCycleDetailComReqDto.setSubjectLifeCycle("CURRENTLY_VALID");//sourceId:1698322_1_66155
            if (reqDto != null) {
                queryTargetContetCycleDetailComReqDto.setEvaObjTargetCycleId(reqDto.getEvaObjTargetCycleId());//SimpleFieldAssign//sourceId:1698318_1_66155
                queryTargetContetCycleDetailComReqDto.setEvaluationTemplateId(reqDto.getEvaluationTemplateId());//SimpleFieldAssign//sourceId:1698359_1_66155
                queryTargetContetCycleDetailComReqDto.setSpaceId(reqDto.getSpaceId());//SimpleFieldAssign//sourceId:1698323_1_66155
            }

            /*D3查询目标内容周期详情(公共)[9284]   */
            Assert.isNull(queryTargetContetCycleDetailComReqDto.getEvaObjTargetCycleId(), "D4执行绩效成果统计-被评对象-D3查询目标内容周期详情(公共)-被评对象目标周期ID不能为空", false);
            Assert.isNull(queryTargetContetCycleDetailComReqDto.getSubjectLifeCycle(), "D4执行绩效成果统计-被评对象-D3查询目标内容周期详情(公共)-主体生命周期不能为空", false);
            Assert.isNull(queryTargetContetCycleDetailComReqDto.getEvaluationTemplateId(), "D4执行绩效成果统计-被评对象-D3查询目标内容周期详情(公共)-冗余评价模板ID不能为空", false);
            Assert.isNull(queryTargetContetCycleDetailComReqDto.getSpaceId(), "D4执行绩效成果统计-被评对象-D3查询目标内容周期详情(公共)-创建于空间ID不能为空", false);
            queryTargetContetCycleDetailComRespDto = fwAppTargetCalcClient.queryTargetContetCycleDetailCom(queryTargetContetCycleDetailComReqDto).getData()/*vcase invoke 跨dubbo调用;*/;


            StatisticsWorkCycleAchievementNumsComRespDto statisticsWorkCycleAchievementNumsComRespDto = null;
            if (queryTargetContetCycleDetailComRespDto != null) {
                StatisticsWorkCycleAchievementNumsComReqDto statisticsWorkCycleAchievementNumsComReqDto = new StatisticsWorkCycleAchievementNumsComReqDto();
                if (queryTargetContetCycleDetailComRespDto != null) {
                    statisticsWorkCycleAchievementNumsComReqDto.setAchievementBelongBodyId(queryTargetContetCycleDetailComRespDto.getEvaObjEntityId());//SimpleFieldAssign//sourceId:1698306_1_66158
                    statisticsWorkCycleAchievementNumsComReqDto.setEvaObjEntityId(queryTargetContetCycleDetailComRespDto.getEvaObjEntityId());//SimpleFieldAssign//sourceId:1698599_1_66158
                    statisticsWorkCycleAchievementNumsComReqDto.setTargetCycleContentId(queryTargetContetCycleDetailComRespDto.getTargetCycleContentId());//SimpleFieldAssign//sourceId:1698846_1_66158
                    statisticsWorkCycleAchievementNumsComReqDto.setCycleId(queryTargetContetCycleDetailComRespDto.getCycleId());//SimpleFieldAssign//sourceId:1698307_1_66158
                    statisticsWorkCycleAchievementNumsComReqDto.setCycleStartTime(queryTargetContetCycleDetailComRespDto.getCycleStartTime());//SimpleFieldAssign//sourceId:1698304_1_66158
                    statisticsWorkCycleAchievementNumsComReqDto.setCycleEndTime(queryTargetContetCycleDetailComRespDto.getCycleEndTime());//SimpleFieldAssign//sourceId:1698305_1_66158
                }
                if (reqDto != null) {
                    statisticsWorkCycleAchievementNumsComReqDto.setEvaObjTypeCode(reqDto.getEvaObjTypeCode());//SimpleFieldAssign//sourceId:1698844_1_66158
                    statisticsWorkCycleAchievementNumsComReqDto.setTargetCycleContentTypeCode(reqDto.getTargetCycleContentTypeCode());//SimpleFieldAssign//sourceId:1698300_1_66158
                    statisticsWorkCycleAchievementNumsComReqDto.setIsLastCycle(reqDto.getIsLastCycle());//SimpleFieldAssign//sourceId:1698303_1_66158
                    statisticsWorkCycleAchievementNumsComReqDto.setParentSubMidCycleType(reqDto.getParentSubMidCycleType());//SimpleFieldAssign//sourceId:1698302_1_66158
                    statisticsWorkCycleAchievementNumsComReqDto.setEvaluationTemplateId(reqDto.getEvaluationTemplateId());//SimpleFieldAssign//sourceId:1698299_1_66158
                    statisticsWorkCycleAchievementNumsComReqDto.setSpaceId(reqDto.getSpaceId());//SimpleFieldAssign//sourceId:1698301_1_66158
                }

                /*D3统计工作周期成果数(公共)[9279]   */
                Assert.isNull(statisticsWorkCycleAchievementNumsComReqDto.getAchievementBelongBodyId(), "D4执行绩效成果统计-被评对象-D3统计工作周期成果数(公共)-成果所属主体ID不能为空", false);
                Assert.isNull(statisticsWorkCycleAchievementNumsComReqDto.getEvaObjEntityId(), "D4执行绩效成果统计-被评对象-D3统计工作周期成果数(公共)-被评对象内容表主键ID不能为空", false);
                Assert.isNull(statisticsWorkCycleAchievementNumsComReqDto.getEvaObjTypeCode(), "D4执行绩效成果统计-被评对象-D3统计工作周期成果数(公共)-被评对象类型编码不能为空", false);
                Assert.isNull(statisticsWorkCycleAchievementNumsComReqDto.getTargetCycleContentTypeCode(), "D4执行绩效成果统计-被评对象-D3统计工作周期成果数(公共)-关联目标内容类型编码不能为空", false);
                Assert.isNull(statisticsWorkCycleAchievementNumsComReqDto.getTargetCycleContentId(), "D4执行绩效成果统计-被评对象-D3统计工作周期成果数(公共)-关联目标内容ID不能为空", false);
                Assert.isNull(statisticsWorkCycleAchievementNumsComReqDto.getIsLastCycle(), "D4执行绩效成果统计-被评对象-D3统计工作周期成果数(公共)-是否末级周期不能为空", false);
                Assert.isNull(statisticsWorkCycleAchievementNumsComReqDto.getParentSubMidCycleType(), "D4执行绩效成果统计-被评对象-D3统计工作周期成果数(公共)-父子中周期类型不能为空", false);
                Assert.isNull(statisticsWorkCycleAchievementNumsComReqDto.getCycleId(), "D4执行绩效成果统计-被评对象-D3统计工作周期成果数(公共)-归属子周期周期ID不能为空", false);
                Assert.isNull(statisticsWorkCycleAchievementNumsComReqDto.getCycleStartTime(), "D4执行绩效成果统计-被评对象-D3统计工作周期成果数(公共)-目标计划开始时间不能为空", false);
                Assert.isNull(statisticsWorkCycleAchievementNumsComReqDto.getCycleEndTime(), "D4执行绩效成果统计-被评对象-D3统计工作周期成果数(公共)-目标计划结束时间不能为空", false);
                Assert.isNull(statisticsWorkCycleAchievementNumsComReqDto.getEvaluationTemplateId(), "D4执行绩效成果统计-被评对象-D3统计工作周期成果数(公共)-冗余评价模板ID不能为空", false);
                Assert.isNull(statisticsWorkCycleAchievementNumsComReqDto.getSpaceId(), "D4执行绩效成果统计-被评对象-D3统计工作周期成果数(公共)-创建于空间ID不能为空", false);
                statisticsWorkCycleAchievementNumsComRespDto = fwAppNullClient.statisticsWorkCycleAchievementNumsCom(statisticsWorkCycleAchievementNumsComReqDto).getData()/*vcase invoke 跨dubbo调用;*/;


                statisticsWorkCycleAchievementNumsComRespDto_1 = statisticsWorkCycleAchievementNumsComRespDto;
            }
        }
        ImplementPerfAchievementStatisticsComRespDto retData = new ImplementPerfAchievementStatisticsComRespDto();
        if (statisticsWorkCycleAchievementNumsComRespDto_1 != null) {
            retData.setCalcCount(statisticsWorkCycleAchievementNumsComRespDto_1.getCalcCount());//SimpleFieldAssign//sourceId:1699001_1
            retData.setAchievementDockingList(statisticsWorkCycleAchievementNumsComRespDto_1.getAchievementDockingList().stream().map(item -> BeanUtil.toBean(item, AchievementDockingDto.class)).collect(Collectors.toList()));//objList-to-objLists//sourceId:1699728_1
        }


        return retData;
    }
    //
}
